package com.atguigu.srb.core.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

@Configuration
@Slf4j
public class MqProducterConfig {

    @Resource
    RabbitTemplate rabbitTemplate;

    @PostConstruct
    public void init(){
                //消息未达到队列的回调
        rabbitTemplate.setReturnCallback((Message message, int replyCode, String replyText, String exchange, String routingKey)->{
            //消息未达到队列
            log.error("消息未到达队列....");
        });
        //消息是否达到交换机的回调
        rabbitTemplate.setConfirmCallback((CorrelationData correlationData, boolean ack, String cause)->{
            if(!ack){
                //消息未达到交换机
                log.error("消息未达到交换机....");
            }
        });
    }

}
